home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / HippoDraw / HippoDrawSrc1.1 / Hippo.subproj / Graphic.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-25  |  7.1 KB  |  267 lines

  1. #import <objc/Object.h>
  2. #import <appkit/graphics.h>
  3. #import <appkit/color.h>
  4.  
  5. #define KNOB_DY_ONCE  0x1
  6. #define KNOB_DY_TWICE 0x2
  7. #define KNOB_DX_ONCE  0x4
  8. #define KNOB_DX_TWICE 0x8
  9.  
  10. /* corners */
  11.  
  12. #define LOWER_LEFT    (0x10)
  13. #define LEFT_SIDE    (KNOB_DY_ONCE)
  14. #define UPPER_LEFT    (LEFT_SIDE|KNOB_DY_TWICE)
  15. #define TOP_SIDE    (UPPER_LEFT|KNOB_DX_ONCE)
  16. #define UPPER_RIGHT    (TOP_SIDE|KNOB_DX_TWICE)
  17. #define BOTTOM_SIDE    (KNOB_DX_ONCE)
  18. #define LOWER_RIGHT    (BOTTOM_SIDE|KNOB_DX_TWICE)
  19. #define RIGHT_SIDE    (LOWER_RIGHT|KNOB_DY_ONCE)
  20.  
  21. /* special corner which means upper right, but also note that we're creating */
  22.  
  23. #define CREATE        (0x20)
  24.  
  25. /* corner mask values */
  26.  
  27. #define LOWER_LEFT_MASK        (1 << LOWER_LEFT)
  28. #define LEFT_SIDE_MASK        (1 << LEFT_SIDE)
  29. #define UPPER_LEFT_MASK        (1 << UPPER_LEFT)
  30. #define TOP_SIDE_MASK        (1 << TOP_SIDE)
  31. #define UPPER_RIGHT_MASK    (1 << UPPER_RIGHT)
  32. #define BOTTOM_SIDE_MASK    (1 << BOTTOM_SIDE)
  33. #define LOWER_RIGHT_MASK    (1 << LOWER_RIGHT)
  34. #define RIGHT_SIDE_MASK        (1 << RIGHT_SIDE)
  35. #define ALL_CORNERS        0xffffffff
  36.  
  37. #define ARROW_AT_START    1
  38. #define ARROW_AT_END    2
  39. #define ARROW_AT_BOTH    3
  40.  
  41. extern id CrossCursor;
  42.  
  43. @interface Graphic : Object
  44. {
  45.     NXRect bounds;            /* the bounds */
  46.     float linewidth;            /* linewidth */
  47.     struct _gFlags {
  48.     unsigned int selected:1;    /* whether selected */
  49.     unsigned int active:1;        /* whether to really draw in draw: */
  50.     unsigned int eofill:1;        /* whether eofilled */
  51.     unsigned int fillColorSet:1;    /* whether to put frame around fill */
  52.     unsigned int downhill:1;    /* Line: direction line goes */
  53.     unsigned int initialized:1;    /* subclass specific */
  54.     unsigned int linewidthSet:1;    /* used when archiving */
  55.     unsigned int lineColorSet:1;        /* used when archiving */
  56.     unsigned int linejoin:2;    /* line join */
  57.     unsigned int linecap:2;        /* line cap */
  58.     unsigned int fill:1;        /* whether filled */
  59.     unsigned int locked:1;        /* locked down? */
  60.     unsigned int arrow:2;        /* arrow position */
  61.     } gFlags;
  62.     NXColor *lineColor;
  63.     NXColor *fillColor;
  64. }
  65.  
  66. /* Factory methods */
  67.  
  68. + showFastRectFills;
  69. + (BOOL)isEditable;
  70. + cursor;
  71.  
  72. /* Initialization method */
  73.  
  74. - init;
  75.  
  76. /* Called when a GraphicView is unarchived */
  77.  
  78. - awake;
  79.  
  80. /* Private methods (for subclassers only) */
  81.  
  82. - setGraphicsState;
  83. - setLineColor;
  84. - setFillColor;
  85. - (int)cornerMask;
  86.  
  87. /* Public routines (called mostly by a GraphicView or subclassers). */
  88.  
  89. - (BOOL)isSelected;
  90. - (BOOL)isActive;
  91. - (BOOL)isLocked;
  92. - select;
  93. - deselect;
  94. - activate;
  95. - deactivate;
  96. - lock;
  97. - unlock;
  98.  
  99. - setCacheable:(BOOL)flag;
  100. - (BOOL)isCacheable;
  101.  
  102. - getBounds:(NXRect *)theRect;
  103. - setBounds:(const NXRect *)aRect;
  104. - (NXRect *)getExtendedBounds:(NXRect *)theRect;
  105.  
  106. - (int)knobHit:(const NXPoint *)point;
  107.  
  108. - draw:(const NXRect *)rect;
  109.  
  110. - moveLeftEdgeTo:(NXCoord *)x;
  111. - moveRightEdgeTo:(NXCoord *)x;
  112. - moveTopEdgeTo:(NXCoord *)y;
  113. - moveBottomEdgeTo:(NXCoord *)y;
  114. - moveHorizontalCenterTo:(NXCoord *)x;
  115. - moveVerticalCenterTo:(NXCoord *)y;
  116.  
  117. - moveBy:(const NXPoint *)offset;
  118. - moveTo:(const NXPoint *)p;
  119. - centerAt:(const NXPoint *)center;
  120. - sizeTo:(const NXSize *)size;
  121. - sizeToNaturalAspectRatio;
  122. - alignToGrid:graphicView;
  123. - sizeToGrid:graphicView;
  124.  
  125. /* Compatibility methods */
  126.  
  127. - replaceWithImage;
  128.  
  129. /* Public routines (called mostly by inspectors and the like). */
  130.  
  131. - setLineWidth:(const float *)value;
  132. - (float)lineWidth;
  133. - setLineColor:(NXColor *)color;
  134. - (NXColor)lineColor;
  135. - setFillColor:(NXColor *)color;
  136. - (NXColor)fillColor;
  137. - setGraphicTextColor:(NXColor *)color;
  138. - (NXColor)textColor;
  139. - changeFont:sender;
  140. - font;
  141. - setGray:(const float *)value;
  142. - (float)gray;
  143. - setFill:(int)mode;
  144. - (int)fill;
  145. - (BOOL)isFilled;
  146. - setLineCap:(int)capValue;
  147. - (int)lineCap;
  148. - setLineArrow:(int)arrowValue;
  149. - (int)lineArrow;
  150. - setLineJoin:(int)joinValue;
  151. - (int)lineJoin;
  152.  
  153. /* What color is most important */
  154.  
  155. - (BOOL)wantsLineColor;
  156. - (BOOL)wantsFillColor;
  157. - (BOOL)wantsTextColor;
  158.  
  159. /* Archiving (must be overridden by subclasses with instance variables) */
  160.  
  161. - write:(NXTypedStream *)stream;
  162. - read:(NXTypedStream *)stream;
  163.  
  164. /* Routines intended to be subclassed for different types of Graphics. */
  165.  
  166. /*
  167.  * Can be overridden to provide more sophisticated size constraining
  168.  * than an aspect ratio (though that is almost always sufficient).
  169.  * For example, Line overrides this to constrain to closes 15 degree angle.
  170.  */
  171.  
  172. - constrainCorner:(int)corner toAspectRatio:(float)aspect;
  173.  
  174. /*
  175.  * Can be overridden to resize the Graphic differently than the
  176.  * default (which is to drag out the bounds), or to do something
  177.  * before and/or after the subclass is resized.  This is called
  178.  * during the default creation method as well (create:in:).
  179.  */
  180.  
  181. - resize:(NXEvent *)event by:(int)corner in:view;
  182.  
  183. /*
  184.  * Possible override candidate for different types of Graphics.
  185.  * Should return YES if the Graphic got created okay.
  186.  * The most common need to override this method is if the creation
  187.  * of the Graphic requires multiple mouseUps and mouseDowns (for
  188.  * an arbitrary arc, for example).
  189.  */
  190.  
  191. - (BOOL)create:(NXEvent *)event in:view;
  192.  
  193. /*
  194.  * Override hit: if you want your subclass to only get selected when the
  195.  * mouse goes down in certain parts of the bounds (not the whole bounds).
  196.  * e.g. Lines only get selected if you click close to them.
  197.  */
  198.  
  199. - (BOOL)hit:(const NXPoint *)point;
  200.  
  201. /*
  202.  * Returns YES if this Graphic can't be seen through.
  203.  * Default behaviour is to return YES if the Graphic isFilled.
  204.  */
  205.  
  206. - (BOOL)isOpaque;
  207.  
  208. /*
  209.  * Returns YES if the Graphic is properly formed (usually this just
  210.  * refers to whether it is big enough to be a real graphic during creation).
  211.  * This is called by create:in:.  By default it returns YES if the Graphic
  212.  * is at least 10.0 by 10.0 pixels in size.
  213.  */
  214.  
  215. - (BOOL)isValid;
  216.  
  217. /*
  218.  * This is the Graphic's natural aspect ratio.  If it doesn't have a natural
  219.  * aspect ratio, then this method should return zero (the default return).
  220.  */
  221.  
  222. - (float)naturalAspectRatio;
  223.  
  224. /*
  225.  * Called repeatedly as the user drags the mouse to create or resize
  226.  * the Graphic.  The default implementation does the right thing.
  227.  * The specified corner should be moved to the specified point.
  228.  */
  229.  
  230. - (int)moveCorner:(int)corner to:(const NXPoint *)point constrain:(BOOL)flag;
  231.  
  232. /*
  233.  * This routine actually draws the graphic.  It should be draw to fit the
  234.  * bounds instance variable.  Be sure to use all the parameters listed in
  235.  * the instance variable list (e.g. linewidth, fillgray, etc.) that are
  236.  * appropriate to this object.  It is probably a good idea to do a newpath
  237.  * and a closepath at the beginning and the end of draw.
  238.  * If a sublcass just wants to draw a unit-sized version of itself
  239.  * (i.e. it draws itself in a bounding box of {{0.0,0.0},{1.0,1.0}})
  240.  * it can just override unitDraw (and not draw).
  241.  */
  242.  
  243. - unitDraw;
  244. - draw;
  245.  
  246. /*
  247.  * Should return YES iff the Graphic can be "edited."  It is up to the
  248.  * subclass of Graphic to determine what this means for it.  Usually
  249.  * it means that it has text and allows that text to be edited by the
  250.  * user (e.g. TextGraphic).  Default is to do nothing and return NO.
  251.  */
  252.  
  253. - (BOOL)edit:(NXEvent *)event in:view;
  254.  
  255.  
  256.  
  257. /* Methods added to support Hippo drawing */
  258.  
  259. - forward:(SEL)aSelector :(marg_list)argFrame;
  260.   /*
  261.    * implemented to trap messages destined to Plot objects.
  262.    * They should be trapped here and be harmless to non-plot objects
  263.    */
  264.    
  265. @end
  266.  
  267.